{extend name="common/base" /}

{block name="title"}<title>{$title}</title>{/block}

{block name="main"}
<div class="layui-fluid table">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form" lwid100="" iwid300="" lay-filter="form">
                        <div class="layui-form-item" style="">
                            <label class="layui-form-label">变量名称</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" placeholder="变量名称" type="text" lay-verify="required" name="name" value="{$name?:''}">
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item" style="">
                            <label class="layui-form-label">变量值</label>
                            <div class="layui-input-inline">
                                <textarea placeholder="变量值" class="layui-textarea"  name="value">{$value??''}</textarea>
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item" style="">
                            <label class="layui-form-label">分组名</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" placeholder="分组名" type="text" lay-verify="required" name="group" value="{$group?:''}">
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item" style="">
                            <label class="layui-form-label">描述</label>
                            <div class="layui-input-inline">
                                <textarea placeholder="变量值" class="layui-textarea"  name="desc">{$desc?:''}</textarea>
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <input type="hidden" name="id" value="{$id?:0}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">更新类型</label>
                            <div class="layui-input-inline">
                                <select name="data_type" lay-filter="aihao"  lay-verify="required">
                                    <option value="1" {if isset($data_type) && $data_type == 1}selected{/if}>string</option>
                                    <option value="2" {if isset($data_type) && $data_type == 2}selected{/if}>int</option>
                                    <option value="3" {if isset($data_type) && $data_type == 3}selected{/if}>json</option>
                                    <option value="4" {if isset($data_type) && $data_type == 4}selected{/if}>bool</option>
                                    <option value="5" {if isset($data_type) && $data_type == 5}selected{/if}>float</option>
                                    <option value="6" {if isset($data_type) && $data_type == 6}selected{/if}>array</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="form">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}


<script>
    {block name="layui_table"}

    var index = parent.layer.getFrameIndex(window.name);

    $('#close').on("click",function () {
        parent.layer.close(index);
    });

    form.on('submit(form)', function(data){
        var data = form.val('form');
        layer.prompt({title: '请输入管理员密码', formType: 1}, function(pass, index1){
            $.ajax({
                url: '/backmanage/config/check_admin'
                ,data: {"code":pass}
                ,type: 'POST'
                ,success(res){
                    if (res.code){
                        layer.close(index1);
                        $.ajax({
                            url: '/backmanage/config/edit'
                            ,data: data
                            ,type: 'POST'
                            ,success(res){
                                if (res.code == 0){
                                    parent.layer.close(index);
                                    parent.layer.msg(res.msg, {icon: 1});
                                    parent.layui.table.reload('table');
                                } else{
                                    layer.msg('操作失败');
                                }
                            }
                        });
                    } else{
                        layer.msg('密码错误');
                    }
                }
            });
            layer.close(index);
        });
    });


    var list_url,cols ='';
    {/block}
</script>

